package com.jeeplus.modules.guide.web;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.FileUtils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.guide.service.MobileLoginService;
import com.jeeplus.modules.guide.service.PDFService;
import com.jeeplus.modules.sys.utils.FileKit;
import com.jeeplus.modules.work.queue.entity.ElectronicMaterialEntity;
import com.jeeplus.modules.work.queue.service.ElectronicMaterialService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import net.sf.json.JSONObject;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

@Api(tags="高新服务pc端扫码接口")
@RestController
@RequestMapping("/qr")
@RequiredArgsConstructor
public class QRController {
    private static final Logger log = LoggerFactory.getLogger(QRController.class);
    private final MobileLoginService mobileLoginService;
    //高馨办pc端二维码扫描地址
    @Value("${qrCheckUrl}")
    private String qrCheckUrl;
    /**
     * 高馨办pc端二维码扫描
     *
     * @return
     */
    @PostMapping(value ="getQRUrl")
    public AjaxJson getQRUrl(){
        String uuid = UUID.randomUUID().toString();
        return AjaxJson.success().put("url",qrCheckUrl+uuid);
    }

    /**
     * 高馨办pc端二维码扫描检测
     *
     * @return
     */
    @PostMapping(value ="checkQR")
    public AjaxJson checkQR(String qrId,String openid){
        return AjaxJson.success("操作成功！").put("token",mobileLoginService.getTokenById(qrId));
    }


}
